package com.iakuil.app.common.core.util;

import com.alibaba.ttl.TransmittableThreadLocal;
import lombok.experimental.UtilityClass;

import java.util.UUID;

/**
 * RequestId工具类
 *
 * @author Kai
 */
@UtilityClass
public class RequestIdUtils {

    private static final ThreadLocal<UUID> REQUEST_ID_HOLDER = new TransmittableThreadLocal<>();

    public static void generateRequestId() {
        REQUEST_ID_HOLDER.set(UUID.randomUUID());
    }

    public static void generateRequestId(UUID uuid) {
        REQUEST_ID_HOLDER.set(uuid);
    }

    public static UUID getRequestId() {
        return REQUEST_ID_HOLDER.get();
    }

    public static void removeRequestId() {
        REQUEST_ID_HOLDER.remove();
    }
}
